<template>
    <div class="mui-numbox" data-numbox-min='1'>
        <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
        <input id="test"
               class="mui-input-numbox"
               type="number" value="1" ref="numbox"
               @change="countChanged"/>
        <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
    </div>
</template>

<script>
    import mui from '../../../../lib/mui/js/mui.js'

    export default {
        name: "",
        props: ['maxcount'], // 在父组件传递之前，maxcount获取到可能是undefined
        data(){
            return {

            }
        },
        mounted(){
            // 初始化数字选择框组件
            mui('.mui-numbox').numbox()
        },
        methods: {
            countChanged(){
                var count = parseInt(this.$refs.numbox.value)
                this.$emit('getcount', count)
            }
        },
        watch: {
            'maxcount': function (newVal) {
                // 监听maxcount，通过jsAPI动态设置最大值
                mui('.mui-numbox').numbox().setOption('max', newVal)
            }
        }
    }
</script>

<style scoped>

</style>